package com.keqing.controller;

import com.ganyu.domain.ResponseResult;
import com.ganyu.domain.dto.AdminRoleDto;
import com.ganyu.domain.dto.AdminUserDto;
import com.ganyu.service.impl.RoleServiceImpl;
import com.ganyu.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * DATA: 2022/9/30
 * Author: 晨夕
 */
@RestController
@RequestMapping("/system/role")
public class AdminRoleController {

    @Autowired
    private RoleServiceImpl roleServiceImpl;

    //查询权限
    @GetMapping("/list")
    public ResponseResult getUserList(Integer pageNum,Integer pageSize,String roleName,String status){
        return roleServiceImpl.getRoleList(pageNum,pageSize,roleName,status);
    }
    @PreAuthorize("@ps.hasPermission()")
    //改变权限
    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(Long roleId ,String status){
        return roleServiceImpl.changeStatus(roleId,status);
    }
    @PreAuthorize("@ps.hasPermission()")
    //新增角色
    @PostMapping
    public ResponseResult addUser(@RequestBody  AdminUserDto adminUserDto){
        return roleServiceImpl.addUser(adminUserDto);
    }
    //根据id查询角色
    @GetMapping("/{id}")
    public ResponseResult selectUserById(@PathVariable("id") Long id){
        return roleServiceImpl.selectUserById(id);
    }
    @PreAuthorize("@ps.hasPermission()")
    //删除角色
    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable("id") Long[] ids){
        return roleServiceImpl.deleteUser(ids);
    }

    //查询所有正常的status的role
    @GetMapping("/listAllRole")
    public ResponseResult selectAllRole(){
        return roleServiceImpl.selectAllRole();
    }
}
